public class Test {

    private static void func(Animal animal) {
        animal.eat();
    }

    private static Animal func2() {
        Dog dog = new Dog("旺财",10);
        return dog;
    }

    public static void main1(String[] args) {
        Animal animal = new Bird("小鸟",11);//向上转型
        Bird bird = (Bird) animal;//向下转型
        bird.fly();
        System.out.println("===========");
        //但是也不是所有的向下转型都是可以成功的
        Animal animal1 = new Dog("旺财",10);
        if(animal1 instanceof Bird){
            Bird bird1 = (Bird) animal1;
            bird1.fly();
        }
    }

    public static void main(String[] args) {
        Dog dog = new Dog("旺财",10);
        func(dog);
        System.out.println("======");
        Bird bird = new Bird("小鸟",11);
        func(bird);
    }
}
